﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 第二次作业第二题
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 点击确定按钮触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void done_Click(object sender, EventArgs e)
        {
            int num = 0;
            int left = Convert.ToInt32(textBox2.Text);
            int right = Convert.ToInt32(textBox1.Text);
            /*判断是否是素数*/
            for (int i = left; i <= right; i++)
            {
                bool flag = true;
                if (i == 1)                                                                         //1情况特殊，剔除
                    flag = false;
                for(int j = 2; j < Convert.ToInt32(Math.Sqrt(i))+1; j++)  //循环只到sqrt
                {
                    if (i % j == 0)
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag == true && num % 10 != 0)
                {
                    textbox.Text = textbox.Text + i.ToString()+ "\t";     //“x20”表示空格
                    num += 1;
                }
                if (flag == true && num % 10 == 0)
                {
                    textbox.Text = textbox.Text  + "\r\n" + i.ToString()+"\t";   //“\r\n”是窗体应用中换行的表达
                    num += 1;
                }

            }
        }
    }
}
